package bancosys.tec.utils.date;

/**
 * {@link Clock} stopped for a certain time. To be used for tests which depends on actions to be done by a fixed time.
 * 
 * @author joao.enomoto
 */
public class StoppedClock implements Clock {

    private Date aDate;

    private Time aTime;

    private Timestamp aTimestamp;

    /**
     * Constructor.
     */
    public StoppedClock() {
        this.aDate = new Date();
        this.aTime = new Time();
        this.aTimestamp = new Timestamp(this.aDate, this.aTime);
    }

    /**
     * Constructor.
     * 
     * @param aTimestamp a timestamp
     */
    public StoppedClock(Timestamp aTimestamp) {
        this.adjustClockTo(aTimestamp);
    }

    /**
     * Constructor.
     * 
     * @param year a year
     * @param month a month
     * @param day a day
     * @param hour an hour
     * @param minute a minute
     * @param second a second
     */
    public StoppedClock(int year, int month, int day, int hour, int minute, int second) {
        this.adjustClockTo(year, month, day, hour, minute, second);
    }

    /**
     * Constructor.
     * 
     * @param year a year
     * @param month a month
     * @param day a day
     * @param hour an hour
     * @param minute a minute
     * @param second a second
     * @param millis milliseconds for date
     */
    public StoppedClock(int year, int month, int day, int hour, int minute, int second, int millis) {
        this.adjustClockTo(year, month, day, hour, minute, second, millis);
    }

    /**
     * Adjust current time to the same time as a parameterized timestamp.
     * 
     * @param anotherTimestamp a timestamp
     */
    public void adjustClockTo(Timestamp anotherTimestamp) {
        this.aDate = new Date(anotherTimestamp);
        this.aTime = new Time(anotherTimestamp);
        this.aTimestamp = anotherTimestamp;
    }

    /**
     * Adjust current time to the same time determined by a group of parameters.
     * 
     * @param year a year
     * @param month a month
     * @param day a day
     * @param hour an hour
     * @param minute a minute
     * @param second a second
     */
    public void adjustClockTo(int year, int month, int day, int hour, int minute, int second) {
        this.adjustClockTo(year, month, day, hour, minute, second, 0);
    }

    /**
     * Adjust current time to the same time determined by a group of parameters.
     * 
     * @param year a year
     * @param month a month
     * @param day a day
     * @param hour an hour
     * @param minute a minute
     * @param second a second
     * @param millis milliseconds for date
     */
    public void adjustClockTo(int year, int month, int day, int hour, int minute, int second, int millis) {
        this.aDate = new Date(year, month, day);
        this.aTime = new Time(hour, minute, second);
        this.aTimestamp = new Timestamp(year, month, day, hour, minute, second, millis);
    }

    /**
     * {@inheritDoc}
     */
    public Date currentDate() {
        return this.aDate;
    }

    /**
     * {@inheritDoc}
     */
    public Time currentTime() {
        return this.aTime;
    }

    /**
     * {@inheritDoc}
     */
    public Timestamp currentTimestamp() {
        return this.aTimestamp;
    }

}
